package com.moodswings;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.maps.Overlay;

import java.util.List;

public class OptionsActivity extends Activity {

	EditText yourname;
	EditText ip;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.options);
		yourname = (EditText) findViewById(R.id.yourname);
		ip = (EditText) findViewById(R.id.ip);
	}

	/**
	 * pri nastavku, pokupi iz preferenci podatke i ispise ih u odgovarajuca polja, da bi korisnik video
	 * sta mu stoji poslednje upisano
	 */
	@Override
	protected void onResume() {
		super.onResume();
		SharedPreferences prefs = getSharedPreferences(MoodSwingsActivity.PREF_NAME, Context.MODE_PRIVATE);
		String ipstring = prefs.getString("IP", "192.168.1.3:8080");
		String idstring = prefs.getString("ID", "USER");
		yourname.setText(idstring);
		ip.setText(ipstring);


	}

	@Override
	protected void onPause() {
		super.onPause();

	}

	/**
	 * upisuje u preference unete podatke
	 */

	public void okButton(View view){
		SharedPreferences prefs = getSharedPreferences(MoodSwingsActivity.PREF_NAME, Context.MODE_PRIVATE);

		//uzmi IP adresu
		String a = ip.getText().toString();

		//uzmi ime korisnika
    	String b = yourname.getText().toString();

		prefs.edit().putString("IP", a).putString("ID", b).commit();

		finish();  //vrati se na prethodni ekran
	}

	/**
	* Cancel dugme ne uzima nikakve preference niti ista menja, samo vraca na main Activity
	*/
	public void cancelButton(View view){
	finish();
	}

}